package com.tianqu.tms.www.cardect.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.TmsDetectInfo;
import com.tianqu.tms.www.cardect.controller.CarWaitConfirmTopListController;
import com.tianqu.tms.www.cardect.viewhelper.CarWaitConfirmViewHelper;
/**
 * 
 * 待确认首页列表页Action
 * 
 * @author tianshifu
 *
 */
public class CarWaitConfirmTopListAction extends TmsAction {
	
	private Logger logger = Logger.getLogger(CarWaitConfirmTopListAction.class);//log
	public final static String PAGENO = "pageNo";
	public final static String SORTKEY = "sortKey";
	public final static String MAXINDEX = "maxIndex";
	public final static String ASC = "asc";
	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		CarWaitConfirmViewHelper view = new CarWaitConfirmViewHelper();
		if(request.getParameter(PAGENO) == null) {
			uc.setAttribute(PAGENO, view.getPageNo());
			uc.setAttribute(SORTKEY, view.getSortKey());
			uc.setAttribute(MAXINDEX, view.getMaxIndex());
			uc.setAttribute(ASC, view.getAsc());
		} else {
			uc.setAttribute(PAGENO, request.getParameter(PAGENO));
			uc.setAttribute(SORTKEY, request.getParameter(SORTKEY));
			uc.setAttribute(MAXINDEX, request.getParameter(MAXINDEX));
			uc.setAttribute(ASC, request.getParameter(ASC));
		}	

		CarWaitConfirmTopListController CarWaitConfirmController = new CarWaitConfirmTopListController();
		CarWaitConfirmController.execute(uc);
		
		view = (CarWaitConfirmViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);
		TmsDetectInfo car = (TmsDetectInfo)uc.getAttribute(CarWaitConfirmTopListController.PAGING);
		
		// viewhelp中设置翻页。
		view.setPageNo(Integer.toString(car.getPageNo()));
		view.setMaxIndex(Integer.toString(car.getMaxIndex()));
		view.setAsc(Boolean.toString(car.isAsc()));
		view.setSortKey(Integer.toString(car.getSortKey()));
		view.setTotalCount(Integer.toString(car.getTotalCount()));
		view.setDateFrom(Integer.toString(car.getDateFrom()));
		view.setDateTo(Integer.toString(car.getDateTo()));
		
		request.setAttribute(TmsConstants.VIEWHELP, view);
		uc.removeAttribute(TmsConstants.VIEWHELP);//移除掉session中的viewhelp值
					
		logger.debug(this.getClass().getName() + "#doAction was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
